<template>
  <div>
    <el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" title="Dialog Titile">
      <el-form ref="elForm" :model="rewardMapping" :rules="rules" size="medium" label-width="100px">
        <el-form-item label="用户" prop="userId">
          <el-select v-model="rewardMapping.userId" placeholder="请选择用户" clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in users" :key="index" :label="item.nickName"
                       :value="item.userId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="奖励" prop="rewardId">
          <el-select v-model="rewardMapping.rewardId" placeholder="请选择奖励" clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in rewards" :key="index" :label="item.rewardName"
                       :value="item.rewardId"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handelConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {addRewardMapping} from "@/api/reward";

export default {
  inheritAttrs: false,
  components: {},
  props: {rewards:[],users:[]},
  data() {
    return {
      rewardMapping: {
        rewardId: undefined,
        userId: undefined,
      },
      rules: {
        rewardId: [{
          required: true,
          message: '请选择奖励',
          trigger: 'change'
        }],
        userId: [{
          required: true,
          message: '请选择用户',
          trigger: 'change'
        }],
      },
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onOpen() {},
    onClose() {
      this.$refs['elForm'].resetFields()
    },
    close() {
      this.$emit('update:visible', false)
    },
    handelConfirm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        addRewardMapping(this.rewardMapping).then(res=>{
          if (res.code===200){
            this.$message.success("添加成功")
            this.$emit("addResult")
          }
        })
        this.close()
      })
    },
  }
}

</script>
<style>
</style>
